View Javadoc

1   package net.sourceforge.simplegamenet.connectaline;
2   
3   import javax.swing.*;
4   import net.sourceforge.simplegamenet.specs.gui.GamePanel;
5   import net.sourceforge.simplegamenet.specs.to.GameSettings;
6   import net.sourceforge.simplegamenet.util.proportionlayout.ProportionConstraints;
7   import net.sourceforge.simplegamenet.util.proportionlayout.ProportionLayout;
8   
9   
10  public class CALPanel extends GamePanel implements CALPlayStyle {
11  
12      private CALPlayerClient cALPlayerClient;
13  
14      private CALPlayFieldPanel cALPlayFieldPanel;
15      private CALPlayerPanel cALPlayerPanel;
16      private JLabel cALMessageLabel = new JLabel(" ");
17      private JLabel cAlPlayStyleLabel = new JLabel("Play style:");
18      private JLabel cAlPlayStyleValueLabel = new JLabel(" ");
19      private JLabel cAlLengthOfLineLabel = new JLabel("Length of a line:");
20      private JLabel cAlLengthOfLineValueLabel = new JLabel(" ");
21  
22  //   private JLabel timeLabel;
23  //   private JLabel timerLabel;
24  
25  
26      public CALPanel(CALPlayerClient cALPlayerClient, GameSettings gameSettings,
27                      JPanel chatClientPanel) {
28          this.cALPlayerClient = cALPlayerClient;
29          cALPlayerPanel = new CALPlayerPanel(cALPlayerClient);
30          cALPlayFieldPanel = new CALPlayFieldPanel(cALPlayerClient,
31                  (CALSettings) gameSettings);
32          ProportionLayout layout = new ProportionLayout();
33          layout.appendColumn(0, 2.0);                            // 0
34          layout.appendColumn(10);                                // 1 empty
35          layout.appendColumn(0, 1.0);                            // 2 cALplayerPanel
36          layout.appendRow(0, ProportionLayout.NO_PROPORTION); // 0 setting labels
37          layout.appendRow(10);                                // 1 empty
38          layout.appendRow(0, ProportionLayout.NO_PROPORTION); // 2 cALplayerPanel
39          layout.appendRow(10);                                // 3 empty
40          layout.appendRow(0, 1.0);                            // 4 chatClientPanel
41          layout.appendRow(10);                                // 5 empty
42          layout.appendRow(0, ProportionLayout.NO_PROPORTION); // 6 cALMessageLabel
43          setLayout(layout);
44  
45  
46          ProportionLayout cAlSettingsLayout = new ProportionLayout();
47          cAlSettingsLayout.appendColumn(0, ProportionLayout.NO_PROPORTION); // 0
48          cAlSettingsLayout.appendColumn(10);                                // 1 empty
49          cAlSettingsLayout.appendColumn(0, 1.0);                            // 2
50          cAlSettingsLayout.appendColumn(10);                                // 3 empty
51          cAlSettingsLayout.appendColumn(0, ProportionLayout.NO_PROPORTION); // 4
52          cAlSettingsLayout.appendColumn(10);                                // 5 empty
53          cAlSettingsLayout.appendColumn(0, 1.0);                            // 6
54          cAlSettingsLayout.appendRow(0, 1.0);                            // 0
55          JPanel cAlSettingsPanel = new JPanel(cAlSettingsLayout);
56          cAlSettingsPanel.add(cAlPlayStyleLabel, new ProportionConstraints(0, 0));
57          cAlSettingsPanel.add(cAlPlayStyleValueLabel, new ProportionConstraints(2, 0));
58          cAlSettingsPanel.add(cAlLengthOfLineLabel, new ProportionConstraints(4, 0));
59          cAlSettingsPanel.add(cAlLengthOfLineValueLabel,
60                  new ProportionConstraints(6, 0));
61          add(cAlSettingsPanel, new ProportionConstraints(0, 0));
62          add(cALPlayFieldPanel, new ProportionConstraints(0, 2, 1, 3, 0, 4));
63          add(cALMessageLabel, new ProportionConstraints(0, 6));
64          add(cALPlayerPanel, new ProportionConstraints(2, 0, 1, 3, 2, 2));
65          add(chatClientPanel, new ProportionConstraints(2, 4, 1, 3, 2, 4));
66          setEnabled(false);
67      }
68  
69      public CALPlayerPanel getCALPlayerPanel() {
70          return cALPlayerPanel;
71      }
72  
73      public void cALSettingsUpdated(CALSettings cALSettings) {
74          cALPlayFieldPanel.cALSettingsUpdated(cALSettings);
75      }
76  
77      public void updateMoveCALPlayFieldPanel() {
78          cALPlayFieldPanel.updateMove();
79      }
80  
81      public int getCALPlayFieldCellWidth() {
82          return cALPlayFieldPanel.getCellWidth();
83      }
84  
85      public int getCALPlayFieldCellHeight() {
86          return cALPlayFieldPanel.getCellHeight();
87      }
88  
89      public void setMessageCALMessagePanel(String cALMessage) {
90          cALMessageLabel.setText(cALMessage);
91      }
92  
93      public void setCALPlayerPanel() {
94          cALPlayerPanel.setCALPlayer();
95      }
96  
97      public void nextCALPlayerPanel() {
98          cALPlayerPanel.nextCALPlayer();
99      }
100 
101     public void removePlayerLabelsPlayerPanel() {
102         cALPlayerPanel.removePlayerLabels();
103     }
104 
105     public void handleTurn() {
106         setEnabled(true);
107         setMessageCALMessagePanel("It's your turn.");
108     }
109 
110     public void setEnabled(boolean enabled) {
111         super.setEnabled(enabled);
112         cALPlayFieldPanel.setEnabled(enabled);
113     }
114 
115     public void setOtherParticipantAtTurn(String nickname) {
116         setMessageCALMessagePanel(nickname + " is playing ");
117     }
118 
119     public void setCALSettings(int cALPlayStyle, int cALLengthOfALine) {
120         switch (cALPlayStyle) {
121             case GRAVITY:
122                 cAlPlayStyleValueLabel.setText("gravity");
123                 break;
124             case ANY_EMPTY_SPOT:
125                 cAlPlayStyleValueLabel.setText("no gravity");
126                 break;
127         }
128         cAlLengthOfLineValueLabel.setText(Integer.toString(cALLengthOfALine));
129     }
130 }